package com.golang.api.function;

import com.golang.api.common.CheckStatusType;
import com.golang.api.common.OrderStatusType;
import com.golang.api.common.SerialCodePrefix;
import com.golang.api.domain.*;
import com.golang.api.dto.request.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.function.Function;

public interface OrderFunction {


    //创建活动基本信息
    default Function<OrderInfoCreateDto, OrderInfo> activityBasic(OrderInfoCreateDto dto) {
        return a -> {
            OrderInfo orderInfo = new OrderInfo()
                    .setActivityId(dto.getActivityId())
                    .setActivityTitle(null)  //活动标题
                    .setOrderId(SerialCodePrefix.splice(SerialCodePrefix.ORDER_ID))
                    .setOrderStatus(OrderStatusType.UnPaid.getDbType())
                    .setDeclaration(dto.getDeclaration())
                    .setRequiredAnswer(dto.getRequiredAnswer());

            orderInfo.setCreateTime(LocalDateTime.now());
            orderInfo.setUpdateTime(orderInfo.getCreateTime());




            return orderInfo;
        };
    }



    default Function<String, OrderPic> OrderPicDto2OrderPic(String pic, String orderNo) {
        return entity -> new OrderPic()
                .setOrderNo(orderNo)
                .setPic(pic);
    }



    default Function<OrderTicketCreateDto, OrderItem> OrderItemDto2OrderItem(OrderTicketCreateDto dto, String orderNo, ActivityTicket ticket) {



        return entity -> new OrderItem()
                .setOrderId(orderNo)
                .setOrderItemId(SerialCodePrefix.splice(SerialCodePrefix.ORDER_ITEM_ID))
                .setOrderStatus(OrderStatusType.UnPaid.getDbType())
                .setCheckStatus(CheckStatusType.UnCheck.ordinal())
                .setTicketName(ticket.getTicketName())
                .setQuantity(dto.getQuantity())
                .setPrice(ticket.getPrice())
                .setAmount(ticket.getPrice().multiply(new BigDecimal(dto.getQuantity())));





    }


}
